<template>
  <div class="home">
    <div class="home-head">
      <el-row :gutter="20">
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <div><i class="el-icon-document"></i></div>
            <div>
              <p class="itemtitle">总订单</p>
              <p class="itemtext">{{ totalOrder }}</p>
            </div>
          </div></el-col
        >
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <div><i class="el-icon-coin"></i></div>
            <div>
              <p class="itemtitle">总销售额</p>
              <p class="itemtext">{{ totalAmount }}</p>
            </div>
          </div></el-col
        >
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <div><i class="el-icon-s-order"></i></div>
            <div>
              <p class="itemtitle">今日订单数</p>
              <p class="itemtext">{{ todayOrder }}</p>
            </div>
          </div></el-col
        >
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <div><i class="el-icon-s-data"></i></div>
            <div>
              <p class="itemtitle">今日销售额</p>
              <p class="itemtext">{{ totayAmount }}</p>
            </div>
          </div></el-col
        >
      </el-row>
    </div>
    <div id="chart"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { $_totaldata } from "@/apis/echarts";
export default {
  mounted() {
    var myChart = echarts.init(document.getElementById("chart"));
    $_totaldata().then((res) => {
      this.totalAmount = res.data.totalAmount;
      this.totalOrder = res.data.totalOrder;
      this.todayOrder = res.data.todayOrder;
      this.totayAmount = res.data.totayAmount;
      myChart.setOption({
        title: {
          text: "数据统计",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["订单数据", "销售数据"],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: res.data.xData,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "订单数据",
            type: "line",

            data: res.data.orderData,
          },
          {
            name: "销售数据",
            type: "line",

            data: res.data.amountData,
          },
        ],
      });
    });
  },
  data() {
    return {
      todayOrder: 0,
      totalAmount: 0,
      totalOrder: 0,
      totayAmount: 0,
    };
  },
};
</script>

<style lang='less' scoped>
.home {
  padding: 10px;
  background-color: #fff;

  .home-head {
    .el-row {
      width: 100%;

      margin-bottom: 20px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      &:last-child {
        margin-bottom: 0;
      }
    }
    .el-col {
      border-radius: 4px;
    }
    .bg-purple-dark {
      background: #99a9bf;
    }
    .bg-purple {
      background: #d3dce6;
    }
    .bg-purple-light {
      background: #e5e9f2;
    }
    .grid-content {
      height: 120px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      border-radius: 4px;
      min-height: 36px;
      .el-icon-document {
        font-size: 80px;
        color: #2196f3;
      }
      .el-icon-coin {
        font-size: 80px;
        color: #e91e63;
      }
      .el-icon-s-order {
        font-size: 80px;
        color: #2196f3;
      }
      .el-icon-s-data {
        font-size: 80px;
        color: #4caf50;
      }
      .itemtext {
        font-size: 20px;
        color: #757575;
      }
      .itemtitle {
        font-size: 30px;
        color: #000;
      }
    }
    .row-bg {
      padding: 10px 0;
      background-color: #f9fafc;
    }
  }
  #chart {
    width: 800px;
    height: 500px;
    margin-top: 30px;
  }
}
</style>